// work/pages/workReport_list/workReport_list.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabList: [{
      label: '草稿箱',
      list: []
    }, {
      label: '已发布',
      list: []
    }, ],
    status: 1, //  0  编辑中   1 已发布
  },


  // 获取数据
  getData() {
    var url = app.globalData.url + "workReport/getWorkReport",
      that = this,
      tabList = this.data.tabList,
      status = this.data.status;
    wx.showLoading({
      title: '',
    })
    app.wxRequest(url, {
      memberId: app.globalData.memberId,
      status
    }, res => {
      console.log(res);
      if (res.flag) {
        res.data = res.data.sort((a, b) => {
          return a.workType - b.workType
        })
        tabList[status].list = res.data
        console.log(tabList);
        wx.hideLoading()
        wx.stopPullDownRefresh()
        that.setData({
          tabList
        })
      }
    })





  },

  // 跳转到详情页
  toDetail(e) {
    console.log(e);
    var obj = e.currentTarget.dataset.obj
    console.log(obj);
    wx.navigateTo({
      url: '/work/pages/workReport/workReport?obj=' + JSON.stringify(obj),
    })

  },
  toAdd() {
    wx.navigateTo({
      url: '/work/pages/workReport/workReport',
    })
  },

  onChange(e) {
    console.log(e);
    this.setData({
      status: e.detail.index
    })
    this.getData()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      status: 0
    })
    this.getData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getData()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})